Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix Group-TotalWeight invariant #13116

Merged
merged 4 commits into from
Sep 1, 2022
Merged

Conversation

alexanderbez
Copy link
Contributor

Description

Closes: #13088

The Group-TotalWeight was poorly implemented as it violates the correct usage of KVStore iterators. This resulted in deadlocks.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@alexanderbez alexanderbez marked this pull request as ready for review August 31, 2022 21:18
@alexanderbez alexanderbez requested a review from a team as a code owner August 31, 2022 21:18
@codecov
Copy link

codecov bot commented Aug 31, 2022

Codecov Report

Merging #13116 (eb7f701) into main (4fe7797) will decrease coverage by 2.72%.
The diff coverage is 47.89%.

❗ Current head eb7f701 differs from pull request most recent head ec5268f. Consider uploading reports for the commit ec5268f to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13116      +/-   ##
==========================================
- Coverage   55.87%   53.15%   -2.73%     
==========================================
  Files         646      641       -5     
  Lines       54895    54874      -21     
==========================================
- Hits        30675    29167    -1508     
- Misses      21762    23383    +1621     
+ Partials     2458     2324     -134     
Impacted Files Coverage Δ
baseapp/abci.go 64.09% <0.00%> (-0.33%) ⬇️
baseapp/options.go 69.23% <ø> (+0.71%) ⬆️
client/context.go 55.37% <0.00%> (-0.91%) ⬇️
client/flags/flags.go 19.35% <0.00%> (-0.32%) ⬇️
client/rpc/status.go 66.66% <ø> (ø)
client/utils.go 34.92% <0.00%> (ø)
server/config/config.go 38.00% <0.00%> (-1.59%) ⬇️
server/mock/store.go 19.00% <0.00%> (-0.39%) ⬇️
server/rollback.go 0.00% <0.00%> (ø)
server/rosetta/client_online.go 1.35% <0.00%> (ø)
... and 130 more

for {
membersWeight, err := groupmath.NewNonNegativeDecFromString("0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this line failing under some conditions? I'm not understanding how the behavior of parsing "0" into a Dec could be anything but invariant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has nothing to do with the fix/changes. The change was to not have nested iterators which a violation of how iterators should be used.

@@ -378,11 +378,14 @@ func (store *Store) clearUnsortedCacheSubset(unsorted []*kv.Pair, sortState sort
if item.Value == nil {
// deleted element, tracked by store.deleted
// setting arbitrary value
store.sortedCache.Set(item.Key, []byte{})
if err := store.sortedCache.Set(item.Key, []byte{}); err != nil {
panic(err)
Copy link
Member

@kocubinski kocubinski Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the line that fixes the bug? the added panic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The fix is breaking up the nested for loops into 2 separate single for loops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a patch while I was debugging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a consensus-breaking change?

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alexanderbez !

What's still unclear to me is why this error appeared only in your CommunitySpend PR.

@@ -378,11 +378,14 @@ func (store *Store) clearUnsortedCacheSubset(unsorted []*kv.Pair, sortState sort
if item.Value == nil {
// deleted element, tracked by store.deleted
// setting arbitrary value
store.sortedCache.Set(item.Key, []byte{})
if err := store.sortedCache.Set(item.Key, []byte{}); err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a consensus-breaking change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulation Failure/Timeout
5 participants